package com.gm.machine.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 权限.
 * 
 * 注释见{@link User}.
 */
@Entity
@Table(name = "acct_authority")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Authority extends BaseEntity
{
    /**
     * serialVersionUID long
     */
    private static final long  serialVersionUID = 1L;

    /**
     * SpringSecurity中默认的角色/授权名前缀.
     */
    public static final String AUTHORITY_PREFIX = "ROLE_";

    private String             name;

    public Authority()
    {
    }

    public Authority(Long id, String name)
    {
        this.id = id;
        this.name = name;
    }

    @Column(nullable = false, unique = true)
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    @Transient
    public String getPrefixedName()
    {
        return AUTHORITY_PREFIX + name;
    }

    @Override
    public String toString()
    {
        return ToStringBuilder.reflectionToString(this);
    }
}
